/**
 * Copyright 2008 Benjamin Possolo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.javenue.util.process;

import org.javenue.util.process.ProcessState;

/**
 * Interface used by implementations of the <tt>TransitionManager</tt> for performing persistence
 * operations on <tt>ProcessState</tt> instances.
 * <p>
 * This interface provides methods for performing the traditional CRU (create, read, update)
 * operations on <tt>ProcessState</tt> instances for any given persistence store.
 * 
 * @author Benjamin Possolo
 * <p>Created on May 12, 2008
 */
public interface ProcessStatePersister {
	
	/**
	 * Saves the new <tt>ProcessState</tt> instance of the persistence store.
	 * <p>
	 * The <code>processState</code> should have a unique identifier value
	 * that does not yet exist in the database.
	 * 
	 * @param processState the <tt>ProcessState</tt> instance to save
	 * @throws PersistenceException if an error occurs communicating with the persistence store
	 */
	void saveNewInstance(ProcessState processState) throws PersistenceException;
	
	/**
	 * Retrieves a <tt>ProcessState</tt> instance from the persistence store.
	 * <p>
	 * The type of <tt>ProcessState</tt> object to retrieve (which may determine where the record
	 * is stored in the persistence store) and the identifier of the object are specified as
	 * parameters.
	 * 
	 * @param processStateClass the runtime class of the <tt>Proces</tt> whose <tt>ProcessState</tt> is to be retrieved
	 * @param id the identifier value of the <tt>Process</tt> whose <tt>ProcessState</tt> is to be retrieved
	 * @return the <tt>ProcessState</tt> instance that corresponds to the given <tt>Process</tt> class and ID value, or null if none exists 
	 * @throws PersistenceException if an error occurs communicating with the persistence store
	 */
	ProcessState getProcessState(Class<? extends ProcessState> processStateClass, Integer id) throws PersistenceException;
	
	/**
	 * Updates the persitent properties of the given <tt>ProcessState</tt> in the persistence store.
	 * <p>
	 * The <code>processState</code> must have a unique identifier that corresponds to an existing
	 * record in the persistence store.
	 * 
	 * @param processState the <tt>ProcessState</tt> instance to update
	 * @throws PersistenceException if an error occurs communicating with the persistence store
	 */
	void persistChanges(ProcessState processState) throws PersistenceException;
}
